﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.WowAddonStudio.FrameXml.Components.Actions;
using Microsoft.WowAddonStudio.FrameXml.Components.Designers;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Components.Support;
using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;
using Action = Microsoft.WowAddonStudio.FrameXml.Components.Actions.Action;
using Color = Microsoft.WowAddonStudio.FrameXml.Serialization.Color;

namespace Microsoft.WowAddonStudio.FrameXml.Components
{
    [ToolboxBitmap(typeof(Label), "Label.bmp")]
    [ToolboxItemFilter("WowAddonStudio", ToolboxItemFilterType.Require)]
    [Designer(typeof(LayoutFrameContainerDesigner))]
    public class FontStringControl : LayoutFrameControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FontStringControl"/> class.
        /// </summary>
        public FontStringControl()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FontStringControl"/> class.
        /// </summary>
        /// <param name="fontString">The font string.</param>
        public FontStringControl(FontString fontString)
            : base(fontString)
        {
        }

        /// <summary>
        /// Gets the type of the serialization object this control manages.
        /// </summary>
        public override Type SerializationObjectType
        {
            get
            {
                return typeof(FontString);
            }
        }

        /// <summary>
        /// Gets the font string.
        /// </summary>
        public FontString FontString
        {
            get { return this.SerializationObject as FontString; }
        }

        /// <summary>
        /// Gets the actions for the control.
        /// </summary>
        /// <returns>
        /// An array of <see cref="Action"/> instances.
        /// </returns>
        public override Action[] GetActions()
        {
            return new Action[]
                       {
                           new SetDefaultValueAction(this, "Shadow")
                               {
                                   DefaultValue = new Shadow
                                                      {
                                                          Color = Color.FromColor(System.Drawing.Color.Black),
                                                          Offset = new Dimension { AbsDimension = new AbsDimension{X=1,Y=-1}}
                                                      }
                               }
                       };
        }

        /// <summary>
        /// Draws the FrameXML control.
        /// </summary>
        /// <param name="graphics">The <see cref="FrameXmlGraphics"/> context to draw to.</param>
        /// <param name="rectangle">The <see cref="Rectangle"/> to draw to.</param>
        public override bool DrawControl(FrameXmlGraphics graphics, Rectangle rectangle)
        {
            return graphics.DrawFontString(FontString, rectangle);
        }

        /// <summary>
        /// Gets the default size of a FrameXML control.
        /// </summary>
        /// <value></value>
        protected override Size DefaultSize
        {
            get { return new Size(80, 20); }
        }
    }
}
